package semaforos;

import java.awt.GridBagLayout;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class LuzSemaforo extends JPanel {
	private static final long serialVersionUID = 1L;
	private String color;
	private boolean active;
	private JLabel lightJLabel = null;

	/**
	 * This is the default constructor
	 */
	public LuzSemaforo(String pColor, boolean pActivate) {
		super();
		initialize();
		color = pColor.toLowerCase();
		active = pActivate;
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(getPreferredSize());
		this.setLayout(new GridBagLayout());
		this.add(getLightJLabel());
	}

	public void setActive(boolean pActive) {
		active = pActive;
		if (active){
			getLightJLabel().setIcon(new ImageIcon(this.getClass().getResource("/circulo_"+ color +".png")));
		}
		else{
			getLightJLabel().setIcon(new ImageIcon(this.getClass().getResource("/circulo_apagado.png")));
		}
	}

	/**
	 * This method initializes lightJLabel	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getLightJLabel() {
		if (lightJLabel == null) {
			lightJLabel = new JLabel();
		}
		return lightJLabel;
	}
}
